<?php
require_once 'FileItem.php';
require_once 'FolderItem.php';
/**
 * Demonstrating the 'Factory' pattern
 * One of the benefits is decoupling of code blocks & objects generated at runtime based on type required
 * @author Sukhbir Singh Grewal
 */
class ItemFactory
{
	public static function create($absolutePath)
	{
		if(empty($absolutePath))
			throw new ExceptionHandler('Invalid argument to generate file object');
		$temp = explode(DIRECTORY_SEPARATOR, trim($absolutePath));
		if(1 < count($temp))
			$filename = $temp[count($temp)-1];
		else
			$filename = $temp[0];
		if(is_dir($absolutePath))
			$item = new FolderItem($absolutePath, $filename);
		else
			$item = new FileItem($absolutePath, $filename);
		return $item;
	} 
}